home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Creator Changer 2.7 / Code & Resource / Creator Changer.dialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-30  |  28.4 KB  |  1,025 lines  |  [TEXT/KAHL]

  1. /**********************************************************************
  2.  *    This file contains the bulk of the program.  All of the dialog box
  3.  *    stuff is performed in this file.
  4.  **********************************************************************/
  5.  
  6. #include    "Creator Changer.h"
  7. #include    "Creator Changer.dialog.h"
  8. #include    "GetFileIcon.h"
  9.  
  10.  
  11. /**********************************************************************
  12.  *    Function Open_DLOG(), this function is a general function for 
  13.  *    opening all of the Dialog boxes in the program.
  14.  **********************************************************************/
  15.  
  16. void Open_DLOG(Dialog_Info *the)
  17.     {
  18.  
  19.     Handle                item_handle;
  20.     static UserItemUPP    proc_for_draw_Chng_dialog=NIL_PTR;
  21.     static UserItemUPP    proc_for_draw_Abot_dialog=NIL_PTR;
  22.     File_Union            temp;
  23.     
  24.     if(proc_for_draw_Chng_dialog==NIL_PTR) proc_for_draw_Chng_dialog=NewUserItemProc(Draw_Chng_Dialog);
  25.     if(proc_for_draw_Abot_dialog==NIL_PTR) proc_for_draw_Abot_dialog=NewUserItemProc(Draw_Abot_Dialog);
  26.         
  27.     the->dialog=GetNewDialog(the->dlog_id, the->storage, IN_FRONT);
  28.     Dialog_Opened=YES;
  29.     Maintain_Menu_Items(FrontWindow());
  30.     
  31.     if(the->dialog==Chng.dialog)
  32.         {
  33.         Make_Pop_Up_Menu(the->menu_id, the->pref_type, the->num_items);
  34.         Set_Dialog_Proc((Handle)proc_for_draw_Chng_dialog, Chng.dialog, CHNG_DLOG_UI);
  35.         if(!Multiple_Files)
  36.             {
  37.             Set_Type_Text(&F_Type, File_Info.fdType);
  38.             Set_Type_Text(&C_Type, File_Info.fdCreator);
  39.             }
  40.         }
  41.     else if(the->dialog==About.dialog) Set_Dialog_Proc((Handle)proc_for_draw_Abot_dialog, About.dialog, ABOUT_DLOG_UI);
  42.     else if(the->dialog==Pref.dialog)
  43.         {
  44.         Get_Dialog_Item_Hndl(the->dialog, PREF_POPUP, &item_handle);
  45.         Handle_Pref_Pop_Up_Menu(the, YES);
  46.         }
  47.     
  48.     }
  49.  
  50.  
  51.  
  52. /**********************************************************************
  53.  *    Function Switch_Chng_Dialog(), this function decides where events
  54.  *    in the Change Dialog box should go.
  55.  **********************************************************************/
  56.  
  57. void Switch_Chng_Dialog(Dialog_Info *the, short item_hit)
  58.     {
  59.     
  60.     switch(item_hit)
  61.         {
  62.         case CHNG_OK:
  63.             Handle_Chng_OK(the->dialog, &the->files, the->num_files, CHNG_CREATOR, CHNG_FILE);
  64.             break;
  65.         case CHNG_POP_UP:
  66.             Handle_Pt_Pop_Up(the->dialog, CHNG_POP_UP, CHNG_CREATOR, CHNG_FILE, NO);
  67.             break;
  68.         case CHNG_CANCEL:
  69.             CloseDialog(the->dialog);
  70.             Done_With_Dialog=YES;
  71.             Dialog_Opened=NO;
  72.             Maintain_Menu_Items(FrontWindow());
  73.             break;
  74.         case CHNG_MKLK:
  75.             Handle_Make_Like(the->dialog, CHNG_FILE, CHNG_CREATOR, NIL_PTR);
  76.             break;
  77.         case CHNG_CRNT_CREATOR:
  78.             if(!Multiple_Files) Set_DLOG_Text_Item(the->dialog, CHNG_CREATOR, C_Type.TEXT);
  79.             break;
  80.         case CHNG_CRNT_TYPE:
  81.             if(!Multiple_Files) Set_DLOG_Text_Item(the->dialog, CHNG_FILE, F_Type.TEXT);
  82.             break;
  83.         default:
  84.             break;
  85.         }
  86.         
  87.     }
  88.  
  89.  
  90. /**********************************************************************
  91.  *    Function Switch_Pt_Dialog(), this function decides where events
  92.  *    in the Edit DITL should go.  This is part of the Preference Dialog.
  93.  **********************************************************************/
  94.  
  95. void Switch_Pt_Dialog(Dialog_Info *the, short item_hit)
  96.     {
  97.     
  98.     short            os=the->num_items;
  99.     
  100.     switch(item_hit-os)
  101.         {
  102.         case P_PT_PM:
  103.             Handle_Pt_Pop_Up(the->dialog, os+P_PT_PM, os+P_PT_CT, os+P_PT_FT, os+P_PT_DS);
  104.             break;
  105.         case P_PT_ADD:
  106.             Handle_Pt_Add_Item(the->dialog, os+P_PT_CT, os+P_PT_FT, os+P_PT_DS);
  107.             break;
  108.         case P_PT_DEL:
  109.             Handle_Pt_Del_Item();
  110.             break;
  111.         case P_PT_GFL:
  112.             Handle_Make_Like(the->dialog, os+P_PT_FT, os+P_PT_CT, NIL_PTR);
  113.             break;
  114.         case P_PT_DON:
  115.             CloseDialog(the->dialog);
  116.             Dialog_Opened=NO;
  117.             the->menu_id=NIL_PTR;
  118.             Maintain_Menu_Items(FrontWindow());
  119.             break;
  120.         default:
  121.             break;
  122.         }
  123.         
  124.     }
  125.  
  126.  
  127. /**********************************************************************
  128.  *    Function Switch_Ac_Dialog(), this function decides where events
  129.  *    in the Auto DITL should go.  This is part of the Preference Dialog.
  130.  **********************************************************************/
  131.  
  132. void Switch_Ac_Dialog(Dialog_Info *the, short item_hit)
  133.     {
  134.     
  135.     short            os=the->num_items;
  136.     
  137.     switch(item_hit-os)
  138.         {
  139.         case P_AC_POPM:
  140.             Handle_Ac_Pop_Up(the->dialog, os+P_AC_POPM, os+P_AC_CHFT, os+P_AC_CTCT, os+P_AC_CTFT);
  141.             break;
  142.         case P_AC_ADD:
  143.             Handle_Ac_Add_Item(the->dialog, os+P_AC_CHFT, os+P_AC_CTCT, os+P_AC_CTFT);
  144.             break;
  145.         case P_AC_DEL:
  146.             Handle_Ac_Del_Item();
  147.             break;
  148.         case P_AC_GFL:
  149.             Handle_Make_Like(the->dialog, os+P_AC_CTFT, os+P_AC_CTCT, os+P_AC_CHFT);
  150.             break;
  151.         case P_AC_DON:
  152.             CloseDialog(the->dialog);
  153.             Dialog_Opened=NO;
  154.             the->menu_id=NIL_PTR;
  155.             Maintain_Menu_Items(FrontWindow());
  156.             break;
  157.         default:
  158.             break;
  159.         }
  160.         
  161.     }
  162.  
  163.  
  164. /**********************************************************************
  165.  *    Function Switch_Abot_Dialog(), this function decides where events
  166.  *    in the About Dialog should go. 
  167.  **********************************************************************/
  168.  
  169. void Switch_Abot_Dialog(Dialog_Info *the, short item_hit)
  170.     {
  171.     
  172.     switch(item_hit)
  173.         {
  174.         case ABOUT_OK:
  175.             CloseDialog(the->dialog);
  176.             Dialog_Opened=NO;
  177.             Maintain_Menu_Items(FrontWindow());
  178.             break;
  179.         default:
  180.             break;
  181.         }
  182.         
  183.     }
  184.  
  185.  
  186. /**********************************************************************
  187.  *    Function Switch_Pref_Dialog(), this function decides where events
  188.  *    in the Preference Dialog box should go.
  189.  **********************************************************************/
  190.  
  191. void Switch_Pref_Dialog(Dialog_Info *the, short item_hit)
  192.     {
  193.     
  194.     switch(item_hit)
  195.         {
  196.         case PREF_POPUP:
  197.             Handle_Pref_Pop_Up_Menu(the, NO);
  198.             break;
  199.         default:
  200.             Handle_Pref_DITL_Item(the, item_hit);
  201.             break;
  202.         }
  203.         
  204.     }
  205.  
  206.  
  207.  
  208. /**********************************************************************
  209.  *    Function Switch_Gnrl_Dialog(), this function decides where events
  210.  *    in the General DITL should go.  This is part of the Preference Dialog.
  211.  **********************************************************************/
  212.  
  213. void Switch_Gnrl_Dialog(Dialog_Info *the, short item_hit)
  214.     {
  215.     
  216.     short            os=the->num_items;
  217.     global_prefs    **rsrc_handle;
  218.     
  219.     switch(item_hit-os)
  220.         {
  221.         case P_GN_OKAC:
  222.             UseResFile(CreatorChangerPref);
  223.                 rsrc_handle=(global_prefs **)GetResource(PREF_GL, 128);
  224.                 (**rsrc_handle).AutoChange=Handle_Check_Item(the->dialog, os+P_GN_OKAC);
  225.                 ChangedResource((Handle)rsrc_handle);
  226.                 UpdateResFile(CreatorChangerPref);
  227.             UseResFile(CreatorChangerApp);
  228.             break;
  229.         case P_GN_QADD:
  230.             UseResFile(CreatorChangerPref);
  231.                 rsrc_handle=(global_prefs **)GetResource(PREF_GL, 128);
  232.                 (**rsrc_handle).DragQuit=Handle_Check_Item(the->dialog, os+P_GN_QADD);
  233.                 ChangedResource((Handle)rsrc_handle);
  234.                 UpdateResFile(CreatorChangerPref);
  235.             UseResFile(CreatorChangerApp);
  236.             break;
  237.         case P_GN_OKBT:
  238.             CloseDialog(the->dialog);
  239.             Dialog_Opened=NO;
  240.             the->menu_id=NIL_PTR;
  241.             Maintain_Menu_Items(FrontWindow());
  242.             break;
  243.         }
  244.         
  245.     }
  246.  
  247.  
  248. /**********************************************************************
  249.  *    Function Handle_Chng_OK(), this function changes the file and 
  250.  *    creator types of the file(s) opened.
  251.  **********************************************************************/
  252.  
  253. void Handle_Chng_OK(DialogPtr the_dialog, AEDescList *the_files, long num_of_files, short creator, short file)
  254.      {
  255.      
  256.      short    register    i;
  257.      short                 temp;
  258.      AEKeyword            key_word;
  259.     DescType            the_type;
  260.     Size                the_size;
  261.      
  262.      temp=Check_Data(the_dialog, file, NO)+Check_Data(the_dialog, creator, NO);
  263.      
  264.     if(temp<TYPE_LEN)
  265.         {
  266.         for(i=1;i<=num_of_files;i++)
  267.             {
  268.             if(Multiple_Files)
  269.                 {
  270.                 AEGetNthPtr(the_files, i, typeFSS, &key_word, &the_type, &The_File_Spec, sizeof(The_File_Spec), &the_size);
  271.                 FSpGetFInfo(&The_File_Spec, &File_Info);
  272.                 }
  273.             Set_Type_Long(NIL_PTR, &File_Info.fdType,    the_dialog, file);
  274.             Set_Type_Long(NIL_PTR, &File_Info.fdCreator, the_dialog, creator);
  275.             FSpSetFInfo(&The_File_Spec, &File_Info);
  276.             }
  277.         Force_Finder_Update(&The_File_Spec);
  278.         if(Multiple_Files) AEDisposeDesc(the_files);
  279.         CloseDialog(the_dialog);
  280.         Done_With_Dialog=YES;
  281.         Dialog_Opened=NO;
  282.         Maintain_Menu_Items(the_dialog);
  283.         }
  284.     else Do_Error(Types_Error_1, EMPTY_STR, Types_Error_2, EMPTY_STR);
  285.     
  286.     }
  287.  
  288.  
  289.  
  290. /**********************************************************************
  291.  *    Function Set_Type_Long(), this function sets the file type of the
  292.  *    specified file.  (converts a string in an edit field to an 
  293.  *    unsigned decimal equivalent).
  294.  **********************************************************************/
  295.  
  296. void Set_Type_Long(Str4 in_string, OSType *out_long,  DialogPtr the_dialog, short ID)
  297.     {
  298.     
  299.     short        i;
  300.     File_Union    file_type;
  301.     
  302.     if(the_dialog!=NIL_PTR) Get_Dialog_Text(in_string, the_dialog, ID);
  303.     for(i=0;i<=TYPE_LEN;i++) file_type.TEXT[i]=in_string[i+1];
  304.     
  305.     *out_long=file_type.LONG;
  306.     
  307.     }
  308.  
  309.  
  310.  
  311. /**********************************************************************
  312.  *    Function Set_Type_Text(), this function sets the text for the file
  313.  *    and creator types given an usigned decimal file / creator type.
  314.  **********************************************************************/
  315.  
  316. void Set_Type_Text(File_Union *the_type, OSType the_long_type)
  317.     {
  318.     
  319.     short        i;
  320.     File_Union    temp;
  321.     
  322.     the_type->TEXT[0]=TYPE_LEN;
  323.     temp.LONG=the_long_type;
  324.     for(i=0;i<=TYPE_LEN;i++) the_type->TEXT[i+1]=temp.TEXT[i];
  325.     
  326.     }
  327.  
  328.  
  329.  
  330. /**********************************************************************
  331.  *    Function Handle_Make_Like(), this function picks a file to use as
  332.  *    a template.
  333.  **********************************************************************/
  334.  
  335. void Handle_Make_Like(DialogPtr the_dialog, short file, short creator, short from_file)
  336.     {
  337.     
  338.     File_Union    f_type, c_type;
  339.     FSSpec        ml_file_spec;
  340.     FInfo        ml_file_info;
  341.     
  342.     if(Pick_File(&ml_file_spec, &ml_file_info, FALSE))
  343.         {
  344.         Set_Type_Text(&f_type, ml_file_info.fdType);
  345.         Set_Type_Text(&c_type, ml_file_info.fdCreator);
  346.         
  347.         if(from_file) Set_DLOG_Text_Item(the_dialog, from_file, f_type.TEXT);
  348.         Set_DLOG_Text_Item(the_dialog, file,    f_type.TEXT);
  349.         Set_DLOG_Text_Item(the_dialog, creator, c_type.TEXT);
  350.         }
  351.     PT_Item_To_Edit=AC_Item_To_Edit=0;
  352.     
  353.     }
  354.  
  355.  
  356.  
  357. /**********************************************************************
  358.  *    Function Handle_Pt_Add_Item(), this function actually does the adding
  359.  *    of the items to the preferences file.
  360.  **********************************************************************/
  361.  
  362. void Handle_Pt_Add_Item(DialogPtr the_dialog, short creator, short file, short description)
  363.     {
  364.     
  365.     short        temp;
  366.     pref_types    **rsrc_handle;
  367.     
  368.     temp=Check_Data(the_dialog, file, NO)+Check_Data(the_dialog, creator, NO)+Check_Data(the_dialog, description, YES);
  369.     
  370.     if(temp<TYPE_LEN)
  371.         {
  372.         UseResFile(CreatorChangerPref);
  373.             rsrc_handle=(pref_types **)NewHandle(sizeof(pref_types));
  374.             
  375.             Get_Dialog_Text((**rsrc_handle).Description, the_dialog, description);
  376.             Get_Dialog_Text((**rsrc_handle).CreatorType, the_dialog, creator);
  377.             Get_Dialog_Text((**rsrc_handle).FileType, the_dialog, file);
  378.             
  379.             AddResource((Handle)rsrc_handle, PREF_PT, Chng.num_items==0 ? Strt_Rsrc : The_pt_Type[Chng.num_items]+1, (**rsrc_handle).Description);
  380.             ChangedResource((Handle)rsrc_handle);
  381.             UpdateResFile(CreatorChangerPref);
  382.             Chng.num_items=Edit.num_items=CountResources(PREF_PT);
  383.             ReleaseResource((Handle)rsrc_handle);
  384.         UseResFile(CreatorChangerApp);
  385.         Make_Pop_Up_Menu(PREF_TYPES_ID, PREF_PT, Chng.num_items);
  386.         PT_Item_To_Edit=0;
  387.         }
  388.     else if(temp<=TYPE_LEN+TYPE_LEN+1)    Do_Error(Types_Error_1, EMPTY_STR, Types_Error_2, EMPTY_STR);
  389.     else if(temp==DESC_LEN+2)            Do_Error(Descr_Error, EMPTY_STR, EMPTY_STR, EMPTY_STR);
  390.     else                                Do_Error(Types_Error_1, Descr_Error, EMPTY_STR, EMPTY_STR);
  391.     
  392.     }
  393.  
  394.  
  395.  
  396. /**********************************************************************
  397.  *    Function Handle_Pt_Del_Item(), this function actually does the
  398.  *    deleting of the item from the preferences file.
  399.  **********************************************************************/
  400.  
  401. void Handle_Pt_Del_Item(void)
  402.     {
  403.     
  404.     short        resource_number, i;
  405.     pref_types    **rsrc_handle;
  406.     
  407.     if(PT_Item_To_Edit)
  408.         {
  409.         UseResFile(CreatorChangerPref);
  410.             resource_number=The_pt_Type[PT_Item_To_Edit];
  411.             rsrc_handle=(pref_types **)NewHandle(sizeof(pref_types));
  412.             rsrc_handle=(pref_types **)GetResource(PREF_PT, resource_number);
  413.             RmveResource((Handle)rsrc_handle);
  414.             ReleaseResource((Handle)rsrc_handle);
  415.             UpdateResFile(CreatorChangerPref);
  416.             for(i=(resource_number+1);i<=The_pt_Type[Chng.num_items];i++)
  417.                 {
  418.                 rsrc_handle=(pref_types **)GetResource(PREF_PT, i);
  419.                 DetachResource((Handle)rsrc_handle);
  420.                 AddResource((Handle)rsrc_handle, PREF_PT, i-1, NIL_PTR);
  421.                 ChangedResource((Handle)rsrc_handle);
  422.                 ReleaseResource((Handle)rsrc_handle);
  423.                 
  424.                 rsrc_handle=(pref_types **)GetResource(PREF_PT, i);
  425.                 RmveResource((Handle)rsrc_handle);
  426.                 ChangedResource((Handle)rsrc_handle);
  427.                 ReleaseResource((Handle)rsrc_handle);
  428.                 }
  429.             UpdateResFile(CreatorChangerPref);
  430.             Chng.num_items=Edit.num_items=CountResources(PREF_PT);
  431.         UseResFile(CreatorChangerApp);
  432.         Make_Pop_Up_Menu(PREF_TYPES_ID, PREF_PT, Chng.num_items);
  433.         PT_Item_To_Edit=0;
  434.         }
  435.     else Do_Error(Bad_Item_Error, EMPTY_STR, EMPTY_STR, EMPTY_STR);
  436.         
  437.     }
  438.  
  439.  
  440.  
  441. /**********************************************************************
  442.  *    Function Handle_Ac_Add_Item(), this function actually does the adding
  443.  *    of the items to the preferences file.
  444.  **********************************************************************/
  445.  
  446. void Handle_Ac_Add_Item(DialogPtr the_dialog, short from_file_id, short to_creator_id, short to_file_id)
  447.     {
  448.     
  449.     OSType        long_from_file;
  450.     short        temp;
  451.     auto_chng    **rsrc_handle;
  452.     Str4        types[100];
  453.                 
  454.     temp=Check_Data(the_dialog, from_file_id, NO)+Check_Data(the_dialog, to_creator_id, NO)+Check_Data(the_dialog, to_file_id, NO);
  455.     
  456.     if(temp<TYPE_LEN)
  457.         {
  458.         Get_Types_From_Prefs(types);
  459.         Set_Type_Long(NIL_PTR, &long_from_file, the_dialog, from_file_id);
  460.         if(Check_File_Type(types, long_from_file)) Do_Error(Bad_CF_Type_1, Bad_CF_Type_2, Bad_CF_Type_3, Bad_CF_Type_4);
  461.         else
  462.             {
  463.             rsrc_handle=(auto_chng **)NewHandle(sizeof(auto_chng));
  464.             
  465.             Get_Dialog_Text((**rsrc_handle).FromFile, the_dialog, from_file_id);
  466.             Get_Dialog_Text((**rsrc_handle).ToCreator, the_dialog, to_creator_id);
  467.             Get_Dialog_Text((**rsrc_handle).ToFile, the_dialog, to_file_id);
  468.             
  469.             Make_Ac_Name((**rsrc_handle).Name, (**rsrc_handle).FromFile, (**rsrc_handle).ToCreator, (**rsrc_handle).ToFile);
  470.             UseResFile(CreatorChangerPref);
  471.                 AddResource((Handle)rsrc_handle, PREF_AC, Auto.num_items==0 ? Strt_Rsrc : The_ac_Type[Auto.num_items]+1, (**rsrc_handle).Name);
  472.                 ChangedResource((Handle)rsrc_handle);
  473.                 UpdateResFile(CreatorChangerPref);
  474.                 Auto.num_items=CountResources(PREF_AC);
  475.             UseResFile(CreatorChangerApp);
  476.             ReleaseResource((Handle)rsrc_handle);
  477.             }
  478.         Make_Pop_Up_Menu(AUTO_CHANGE_ID, PREF_AC, Auto.num_items);
  479.         AC_Item_To_Edit=0;
  480.         }
  481.     else Do_Error(Types_Error_1, EMPTY_STR, EMPTY_STR, EMPTY_STR);
  482.     
  483.     }
  484.  
  485.  
  486.  
  487. /**********************************************************************
  488.  *    Function Make_Ac_Name(), this function makes the name
  489.  *    which shows up in the pop-up menu for the auto change items.
  490.  **********************************************************************/
  491.  
  492. void Make_Ac_Name(StringPtr name, StringPtr from_file, StringPtr to_creator, StringPtr to_file)
  493.     {
  494.     
  495.     register short i;
  496.     
  497.     name[0]=16;
  498.     for(i=1;i<=4;i++) name[i]=from_file[i];
  499.     name[5]='-';
  500.     name[6]='>';
  501.     for(i=7;i<=10;i++) name[i]=to_creator[i-6];
  502.     name[11]=',';
  503.     name[12]=' ';
  504.     for(i=13;i<=16;i++) name[i]=to_file[i-12];
  505.     
  506.     }
  507.  
  508.  
  509. /**********************************************************************
  510.  *    Function Handle_Ac_Del_Item(), this function deletes items 
  511.  *    from the auto change item list.
  512.  **********************************************************************/
  513.  
  514. void Handle_Ac_Del_Item(void)
  515.     {
  516.     
  517.     short        resource_number, i;
  518.     auto_chng    **rsrc_handle;
  519.     
  520.     if(AC_Item_To_Edit)
  521.         {
  522.         UseResFile(CreatorChangerPref);
  523.             resource_number=The_ac_Type[AC_Item_To_Edit];
  524.             rsrc_handle=(auto_chng **)NewHandle(sizeof(auto_chng));
  525.             rsrc_handle=(auto_chng **)GetResource(PREF_AC, resource_number);
  526.             RmveResource((Handle)rsrc_handle);
  527.             ReleaseResource((Handle)rsrc_handle);
  528.             UpdateResFile(CreatorChangerPref);
  529.             for(i=(resource_number+1);i<=The_ac_Type[Auto.num_items];i++)
  530.                 {
  531.                 rsrc_handle=(auto_chng **)GetResource(PREF_AC, i);
  532.                 DetachResource((Handle)rsrc_handle);
  533.                 AddResource((Handle)rsrc_handle, PREF_AC, i-1, NIL_PTR);
  534.                 ChangedResource((Handle)rsrc_handle);
  535.                 ReleaseResource((Handle)rsrc_handle);
  536.                 
  537.                 rsrc_handle=(auto_chng **)GetResource(PREF_AC, i);
  538.                 RmveResource((Handle)rsrc_handle);
  539.                 ChangedResource((Handle)rsrc_handle);
  540.                 ReleaseResource((Handle)rsrc_handle);
  541.                 }
  542.             UpdateResFile(CreatorChangerPref);
  543.             Auto.num_items=CountResources(PREF_AC);
  544.         UseResFile(CreatorChangerApp);
  545.         Make_Pop_Up_Menu(AUTO_CHANGE_ID, PREF_AC, Auto.num_items);
  546.         AC_Item_To_Edit=0;
  547.         }
  548.     else Do_Error(Bad_Item_Error, EMPTY_STR, EMPTY_STR, EMPTY_STR);
  549.     
  550.     }
  551.  
  552.  
  553. /**********************************************************************
  554.  *    Function Handle_Check_Item(), this function either checks or 
  555.  *    unchecks a check box item.
  556.  **********************************************************************/
  557.  
  558. Boolean Handle_Check_Item(DialogPtr the_dialog, short dialog_item)
  559.     {
  560.     
  561.     Boolean    value;
  562.     Handle        the_handle;
  563.     
  564.     Get_Dialog_Item_Hndl(the_dialog, dialog_item, &the_handle);
  565.     value=GetCtlValue((ControlHandle)the_handle);
  566.     
  567.     if(value==TRUE)
  568.         {
  569.         SetCtlValue((ControlHandle)the_handle, FALSE);
  570.         return(FALSE);
  571.         }
  572.     else if(value==FALSE)
  573.         {
  574.         SetCtlValue((ControlHandle)the_handle, TRUE);
  575.         return(TRUE);
  576.         }
  577.     
  578.     }
  579.  
  580.  
  581. /**********************************************************************
  582.  *    Function Draw_Default_Border(), this function draws the border
  583.  *    around the item sent to it, that is within the specified dialog box
  584.  **********************************************************************/
  585.  
  586. void Draw_Border(DialogPtr the_dialog, short the_item, short is_default)
  587.     {
  588.     
  589.     short        diameter;
  590.     Rect        item_rect;
  591.     GrafPtr        old_port;
  592.     
  593.     GetPort(&old_port);
  594.     SetPort(the_dialog);
  595.     
  596.     Get_Dialog_Item_Rect(the_dialog, the_item, &item_rect);
  597.     if(is_default)
  598.         {
  599.         diameter=(item_rect.bottom-item_rect.top)/2+6;
  600.         if(diameter<16) diameter=16;
  601.         PenSize(3, 3);
  602.         InsetRect(&item_rect, -4, -4);
  603.         FrameRoundRect(&item_rect, diameter, diameter);
  604.         }
  605.     else
  606.         {
  607.         PenSize(1, 1);
  608.         FrameRect(&item_rect);
  609.         }
  610.         
  611.     SetPort(old_port);
  612.     
  613.     }
  614.  
  615.  
  616.  
  617. /**********************************************************************
  618.  *    Function Draw_Chng_Crnt_Type(), this function handels what happens 
  619.  *    if a key is pressed.
  620.  **********************************************************************/
  621.  
  622. void Draw_Chng_Crnt_Type(DialogPtr the_dialog)
  623.     {
  624.     
  625.     Rect    item_rect;
  626.     GrafPtr    old_port;
  627.     
  628.     TextFont(systemFont);
  629.     TextSize(12);
  630.     TextFace(0);
  631.     
  632.     GetPort(&old_port);
  633.     SetPort(the_dialog);
  634.     
  635.     Draw_Border(the_dialog, CHNG_CRNT_CREATOR, NO);
  636.     Get_Dialog_Item_Rect(the_dialog, CHNG_CRNT_CREATOR, &item_rect);
  637.     MoveTo(item_rect.left+4, item_rect.bottom-7);
  638.     DrawString(C_Type.TEXT);
  639.     
  640.     Draw_Border(the_dialog, CHNG_CRNT_TYPE, NO);
  641.     Get_Dialog_Item_Rect(the_dialog, CHNG_CRNT_TYPE, &item_rect);
  642.     MoveTo(item_rect.left+4, item_rect.bottom-7);
  643.     DrawString(F_Type.TEXT);
  644.     
  645.     SetPort(old_port);
  646.     
  647.     }
  648.  
  649.  
  650.  
  651. /**********************************************************************
  652.  *    Function Check_Data(), this function checks the type entered
  653.  *    by the user.  If there are more than 4 charachters than there is 
  654.  *    an error, and if there is no data entered in there is an error.
  655.  **********************************************************************/
  656.  
  657. short Check_Data(DialogPtr the_dialog, short ID, short is_desc)
  658.     {
  659.     
  660.     Str255        the_error;
  661.     short        the_type_len, len;
  662.     Str32        item_text;
  663.     
  664.     Get_Dialog_Text(item_text, the_dialog, ID);
  665.     len=item_text[0];
  666.     if(is_desc) the_type_len=DESC_LEN;
  667.     else the_type_len=TYPE_LEN;
  668.     if(len!=the_type_len && the_type_len==TYPE_LEN) return(TYPE_LEN);
  669.     else if((len>the_type_len && the_type_len==DESC_LEN) || len==0) return(DESC_LEN);
  670.     else return(GOOD);
  671.     
  672.     }
  673.  
  674.  
  675.  
  676. /**********************************************************************
  677.  *    Function Set_DLOG_Text_Item(), this function sets text boxes in the
  678.  *    selected dialog to the text which is sent to it.
  679.  **********************************************************************/
  680.  
  681. void Set_DLOG_Text_Item(DialogPtr the_dialog, short ID, StringPtr the_text)
  682.     {
  683.     
  684.     Handle        the_handle;
  685.     
  686.     Get_Dialog_Item_Hndl(the_dialog, ID, &the_handle);
  687.     SetIText(the_handle, the_text);
  688.     
  689.     }
  690.  
  691.  
  692.  
  693. /**********************************************************************
  694.  *    Function Draw_Chng_Dialog(), this function draws the objects in the
  695.  *    Change dialog box.
  696.  **********************************************************************/
  697.  
  698. static pascal void Draw_Chng_Dialog(DialogPtr the_dialog, short blank_item)
  699.     {
  700.     
  701.     Rect        item_rect;
  702.     GrafPtr        old_port;
  703.     
  704.     GetPort(&old_port);
  705.     SetPort(the_dialog);
  706.     
  707.     if(!Multiple_Files)
  708.         {
  709.         Get_Dialog_Item_Rect(the_dialog, CHNG_ICON, &item_rect);
  710.         PlotIconSuite(&item_rect, 0, 0, The_Icons);
  711.         Draw_Chng_Crnt_Type(the_dialog);
  712.         }
  713.     Draw_Border(the_dialog, CHNG_OK, YES);
  714.     
  715.     SetPort(old_port);
  716.  
  717.     }
  718.     
  719.  
  720.  
  721. /**********************************************************************
  722.  *    Function Draw_Abot_Dialog(), this function draws the objects in the
  723.  *    About dialog box.
  724.  **********************************************************************/
  725.  
  726. static pascal void Draw_Abot_Dialog(DialogPtr the_dialog, short blank_item)
  727.     {
  728.     
  729.     GrafPtr        old_port;
  730.     
  731.     GetPort(&old_port);
  732.     SetPort(the_dialog);
  733.     
  734.     Draw_Border(the_dialog, ABOUT_OK, YES);
  735.     
  736.     SetPort(old_port);
  737.     
  738.     }
  739.  
  740.  
  741.  
  742. /**********************************************************************
  743.  *    Function 
  744.  **********************************************************************/
  745.  
  746. static pascal void Draw_Pref_Dialog(DialogPtr the_dialog, short blank_item)
  747.     {
  748.         
  749.     Draw_Pref_Border(the_dialog, NIL_PTR);
  750.     if(Pref.menu_id==P_EPTYPE_ITEM) Draw_Pref_Pt(the_dialog, NIL_PTR);
  751.     if(Pref.menu_id==P_EATYPE_ITEM) Draw_Pref_Ac(the_dialog, NIL_PTR);
  752.     if(Pref.menu_id==P_GENERL_ITEM) Draw_Pref_Gnrl(the_dialog, NIL_PTR);
  753.     
  754.     }
  755.  
  756.  
  757.  
  758. /**********************************************************************
  759.  *    Function Draw_Pref_Pt(), this function draws the objects in the
  760.  *    Preference dialog box with respecto the Preferend Types DITL.
  761.  **********************************************************************/
  762.  
  763. static pascal void Draw_Pref_Pt(DialogPtr the_dialog, short blank_item)
  764.     {
  765.     
  766.     short        os=Pref.num_items;
  767.     GrafPtr        old_port;
  768.     
  769.     GetPort(&old_port);
  770.     SetPort(the_dialog);
  771.     
  772.     Draw_Border(the_dialog, os+P_PT_DON, YES);
  773.     
  774.     SetPort(old_port);
  775.     
  776.     }
  777.  
  778.  
  779.  
  780. /**********************************************************************
  781.  *    Function Draw_Pref_Ac(), this function draws the objects in the
  782.  *    Preference dialog box with respecto the Automatic Types DITL.
  783.  **********************************************************************/
  784.  
  785. static pascal void Draw_Pref_Ac(DialogPtr the_dialog, short blank_item)
  786.     {
  787.     
  788.     short        os=Pref.num_items;
  789.     GrafPtr        old_port;
  790.     
  791.     GetPort(&old_port);
  792.     SetPort(the_dialog);
  793.     
  794.     Draw_Border(the_dialog, os+P_AC_DON, YES);
  795.     
  796.     SetPort(old_port);
  797.     
  798.     }
  799.  
  800.  
  801.  
  802. /**********************************************************************
  803.  *    Function Draw_Pref_Gnrl(), this function draws the objects in the
  804.  *    Preference dialog box with respecto the General DITL.
  805.  **********************************************************************/
  806.  
  807. static pascal void Draw_Pref_Gnrl(DialogPtr the_dialog, short blank_item)
  808.     {
  809.     
  810.     Handle        item_handle;
  811.     short        os=Pref.num_items;
  812.     GrafPtr        old_port;
  813.     
  814.     GetPort(&old_port);
  815.     SetPort(the_dialog);
  816.         
  817.     Get_Dialog_Item_Hndl(the_dialog, os+P_GN_OKAC, &item_handle);
  818.     SetCtlValue((ControlHandle)item_handle, (**Global).AutoChange);
  819.     Get_Dialog_Item_Hndl(the_dialog, os+P_GN_QADD, &item_handle);
  820.     SetCtlValue((ControlHandle)item_handle, (**Global).DragQuit);
  821.     Draw_Border(the_dialog, os+P_GN_OKBT, YES);
  822.     
  823.     SetPort(old_port);
  824.     
  825.     }
  826.  
  827.  
  828.  
  829. /**********************************************************************
  830.  *    Function Draw_Pref_Border(), this function  draws the box which 
  831.  *    is shown in the Preference dialog.
  832.  **********************************************************************/
  833.  
  834. static pascal void Draw_Pref_Border(DialogPtr the_dialog, short blank_item)
  835.     {
  836.     
  837.     short        i;
  838.     Rect        item_rect;
  839.     GrafPtr        old_port;
  840.     
  841.     GetPort(&old_port);
  842.     SetPort(the_dialog);
  843.     
  844.     PenSize(1, 1);
  845.     for(i=2;i<=6;i++)
  846.         {
  847.         Get_Dialog_Item_Rect(the_dialog, i, &item_rect);
  848.         FrameRect(&item_rect);
  849.         }
  850.         
  851.     SetPort(old_port);
  852.     
  853.     }
  854.  
  855.  
  856.  
  857. /**********************************************************************
  858.  *    Function Handle_Pref_Set_Up_DLOG(), this function  appends the new 
  859.  *    dialog items to the main preference dialog.
  860.  **********************************************************************/
  861.  
  862. void Handle_Pref_Set_Up_DLOG(DialogPtr the_dialog, short the_ditl, short *ditl_count)
  863.     {
  864.     
  865.     Handle            ditl_handle;
  866.     
  867.     ditl_handle=GetResource( 'DITL', the_ditl);
  868.     
  869.     HLock(ditl_handle);
  870.     AppendDITL(the_dialog, ditl_handle, overlayDITL);
  871.     HUnlock(ditl_handle);
  872.     ReleaseResource(ditl_handle);
  873.     
  874.     *ditl_count=CountDITL(the_dialog);
  875.     
  876.     }
  877.  
  878.  
  879.  
  880. /**********************************************************************
  881.  *    Function Handle_Pref_Pop_Up_Menu(), this function updates  
  882.  *    and sets up the pop-up menu which decides which dialog
  883.  *    items are displayed.
  884.  **********************************************************************/
  885.  
  886. void Handle_Pref_Pop_Up_Menu(Dialog_Info *the, short first_time)
  887.     {
  888.     
  889.     Handle                    item_handle;
  890.     short                    control_value, num_items;
  891.     static UserItemUPP        proc_for_draw_Pref_dialog=NIL_PTR;
  892.     
  893.     if(proc_for_draw_Pref_dialog==NIL_PTR) proc_for_draw_Pref_dialog=NewUserItemProc(Draw_Pref_Dialog);
  894.     
  895.     Get_Dialog_Item_Hndl(the->dialog, PREF_POPUP, &item_handle);
  896.     control_value=GetControlValue((ControlHandle)item_handle);
  897.     if(the->menu_id!=control_value)
  898.         {
  899.         the->menu_id=control_value;
  900.         if(!first_time) ShortenDITL(the->dialog, CountDITL(the->dialog)-PREF_MAX_ITEMS);
  901.         Handle_Pref_Set_Up_DLOG(the->dialog, PREF_DLOG_ID+the->menu_id, &num_items);
  902.         Set_Dialog_Proc((Handle)proc_for_draw_Pref_dialog, the->dialog, num_items);
  903.         switch(control_value)
  904.             {
  905.             case P_EPTYPE_ITEM:
  906.                 Make_Pop_Up_Menu(Edit.menu_id, Edit.pref_type, Edit.num_items);
  907.                 break;
  908.             case P_EATYPE_ITEM:
  909.                 Make_Pop_Up_Menu(Auto.menu_id, Auto.pref_type, Auto.num_items);
  910.                 break;
  911.             }
  912.         }
  913.     
  914.     }
  915.  
  916.  
  917.  
  918. /**********************************************************************
  919.  *    Function Handle_Pref_DITL_Item(), this function ACTUALLY decides where to
  920.  *    to direct an event if it wasn't for the main preference dialog items.
  921.  **********************************************************************/
  922.  
  923. void Handle_Pref_DITL_Item(Dialog_Info *the, short item_hit)
  924.     {
  925.     
  926.     switch(the->menu_id)
  927.         {
  928.         case P_EPTYPE_ITEM:
  929.             Switch_Pt_Dialog(the, item_hit);
  930.             break;
  931.         case P_EATYPE_ITEM:
  932.             Switch_Ac_Dialog(the, item_hit);
  933.             break;
  934.         case P_GENERL_ITEM:
  935.             Switch_Gnrl_Dialog(the, item_hit);
  936.             break;
  937.         default:
  938.             break;
  939.         }
  940.     
  941.     }
  942.  
  943.  
  944.  
  945. /**********************************************************************
  946.  *    Function Get_Dialog_Text), this function 
  947.  **********************************************************************/
  948.  
  949. void Get_Dialog_Text(StringPtr the_string, DialogPtr the_dialog, short the_item)
  950.     {
  951.     
  952.     Handle        item_handle;
  953.     
  954.     Get_Dialog_Item_Hndl(the_dialog, the_item, &item_handle);
  955.     GetIText(item_handle, the_string);
  956.     
  957.     }
  958.  
  959.  
  960.  
  961. /**********************************************************************
  962.  *    Function Set_Dialog_Proc(), this function 
  963.  **********************************************************************/
  964.  
  965. void Set_Dialog_Proc(Handle the_proc, DialogPtr the_dialog, short the_item)
  966.     {
  967.     
  968.     Handle        item_handle;
  969.     short        item_type;
  970.     Rect        item_rect;
  971.     
  972.     GetDItem(the_dialog, the_item, &item_type, &item_handle, &item_rect);
  973.     SetDItem(the_dialog, the_item, item_type, the_proc, &item_rect);
  974.     
  975.     }
  976.  
  977.  
  978.  
  979. /**********************************************************************
  980.  *    Function Get_Dialog_Item_Hndl(), this function 
  981.  **********************************************************************/
  982.  
  983. void Get_Dialog_Item_Hndl(DialogPtr the_dialog, short the_item, Handle *the_handle)
  984.     {
  985.     
  986.     short        item_type;
  987.     Rect        item_rect;
  988.     
  989.     GetDItem(the_dialog, the_item, &item_type, the_handle, &item_rect);
  990.     
  991.     }
  992.  
  993.  
  994.  
  995. /**********************************************************************
  996.  *    Function Get_Dialog_Item_Rect(), this function 
  997.  **********************************************************************/
  998.  
  999. void Get_Dialog_Item_Rect(DialogPtr the_dialog, short the_item, Rect *the_rect)
  1000.     {
  1001.     
  1002.     Handle        item_handle;
  1003.     short        item_type;
  1004.     
  1005.     GetDItem(the_dialog, the_item, &item_type, &item_handle, the_rect);
  1006.     
  1007.     }
  1008.  
  1009.  
  1010.  
  1011. /**********************************************************************
  1012.  *    Function Get_Dialog_Item_In_Rect(), this function 
  1013.  **********************************************************************/
  1014.  
  1015. Boolean Get_Dialog_Item_In_Rect(DialogPtr the_dialog, short the_item, Point the_point)
  1016.     {
  1017.     
  1018.     Rect    item_rect;
  1019.     
  1020.     Get_Dialog_Item_Rect(the_dialog, the_item, &item_rect);
  1021.     if(PtInRect(the_point, &item_rect)) return(YES);
  1022.     return(NO);
  1023.     
  1024.     }
  1025.